package org.apache.commons.httpclient.util;

import org.apache.commons.httpclient.NameValuePair;

public class ParameterFormatter
{
  private static final char[] SEPARATORS;
  private static final char[] UNSAFE_CHARS;
  private boolean alwaysUseQuotes = true;

  static
  {
    char[] arrayOfChar1 = new char[19];
    arrayOfChar1[0] = 40;
    arrayOfChar1[1] = 41;
    arrayOfChar1[2] = 60;
    arrayOfChar1[3] = 62;
    arrayOfChar1[4] = 64;
    arrayOfChar1[5] = 44;
    arrayOfChar1[6] = 59;
    arrayOfChar1[7] = 58;
    arrayOfChar1[8] = 92;
    arrayOfChar1[9] = 34;
    arrayOfChar1[10] = 47;
    arrayOfChar1[11] = 91;
    arrayOfChar1[12] = 93;
    arrayOfChar1[13] = 63;
    arrayOfChar1[14] = 61;
    arrayOfChar1[15] = 123;
    arrayOfChar1[16] = 125;
    arrayOfChar1[17] = 32;
    arrayOfChar1[18] = 9;
    SEPARATORS = arrayOfChar1;
    char[] arrayOfChar2 = new char[2];
    arrayOfChar2[0] = 34;
    arrayOfChar2[1] = 92;
    UNSAFE_CHARS = arrayOfChar2;
  }

  public static void formatValue(StringBuffer paramStringBuffer, String paramString, boolean paramBoolean)
  {
    if (paramStringBuffer == null)
      throw new IllegalArgumentException("String buffer may not be null");
    if (paramString == null)
      throw new IllegalArgumentException("Value buffer may not be null");
    if (paramBoolean)
    {
      paramStringBuffer.append('"');
      for (int l = 0; l < paramString.length(); ++l)
      {
        char c2 = paramString.charAt(l);
        if (isUnsafeChar(c2))
          paramStringBuffer.append('\\');
        paramStringBuffer.append(c2);
      }
      paramStringBuffer.append('"');
    }
    while (true)
    {
      return;
      int i = paramStringBuffer.length();
      int j = 0;
      for (int k = 0; k < paramString.length(); ++k)
      {
        char c1 = paramString.charAt(k);
        if (isSeparator(c1))
          j = 1;
        if (isUnsafeChar(c1))
          paramStringBuffer.append('\\');
        paramStringBuffer.append(c1);
      }
      if (j == 0)
        continue;
      paramStringBuffer.insert(i, '"');
      paramStringBuffer.append('"');
    }
  }

  private static boolean isOneOf(char[] paramArrayOfChar, char paramChar)
  {
    int i = 0;
    if (i < paramArrayOfChar.length)
      label2: if (paramChar != paramArrayOfChar[i]);
    for (int j = 1; ; j = 0)
    {
      return j;
      ++i;
      break label2:
    }
  }

  private static boolean isSeparator(char paramChar)
  {
    return isOneOf(SEPARATORS, paramChar);
  }

  private static boolean isUnsafeChar(char paramChar)
  {
    return isOneOf(UNSAFE_CHARS, paramChar);
  }

  public String format(NameValuePair paramNameValuePair)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    format(localStringBuffer, paramNameValuePair);
    return localStringBuffer.toString();
  }

  public void format(StringBuffer paramStringBuffer, NameValuePair paramNameValuePair)
  {
    if (paramStringBuffer == null)
      throw new IllegalArgumentException("String buffer may not be null");
    if (paramNameValuePair == null)
      throw new IllegalArgumentException("Parameter may not be null");
    paramStringBuffer.append(paramNameValuePair.getName());
    String str = paramNameValuePair.getValue();
    if (str == null)
      return;
    paramStringBuffer.append("=");
    formatValue(paramStringBuffer, str, this.alwaysUseQuotes);
  }

  public boolean isAlwaysUseQuotes()
  {
    return this.alwaysUseQuotes;
  }

  public void setAlwaysUseQuotes(boolean paramBoolean)
  {
    this.alwaysUseQuotes = paramBoolean;
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     org.apache.commons.httpclient.util.ParameterFormatter
 * JD-Core Version:    0.5.3
 */